﻿// **************************************************************************
// *  File: basic.js
// *  (c) Extreme Portal portal 2009-2011
// *  By elwizard. All rights reserved.
// *  http://www.desarrollo-mkportal.org
// *
// *  This program is free software under Extreme Portal License Agreement. 
// *  You cannot distribute in any way. For modifications, please read 
// *  Extreme Portal License Agreement for more information.
// *
// **************************************************************************


objeto=0;
function agregar1() {
	objeto=objeto+1;
	$("#campos").append('<p class="variable'+objeto+'">&nbsp;&nbsp;&nbsp;Variable disseny (clau) '+objeto+': &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Valor (apartat variador) per referència :'
	                   +'<br /><input type="text" name="variables[]" size="30" value="" />&nbsp;<input type="text" name="myvalues[]" size="50" /> <a href="" onclick="javascript:borrar1('+objeto+'); return false;"><img src=\"images/site/minus_.png\" alt=\"Esborrar\" border=\"0\" /></a><br />'
	                   +'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tipus : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Informació de la variable :<br />'
	                   +'<select size="1" name="vtype['+objeto+']" style="border: 1px solid #000000; font-size: 14px;">'
	                   +'<option value="1">Sel.leccioni</option>\n'
	                   +'<option value="1">1. Sistema text field (una fila)</option>\n'
 	                   +'<option value="2">2. Sistema text area (2 o més files)</option>\n'
 	                   +'<option value="3">3. Sistema multi-ús STYLE</option>\n'
 	                   +'</select> <input type="text" name="vinfor['+objeto+']" size="45" value="">'
 	                   +'</p>');
}
function borrar1(cual) {
	$("p.variable"+cual).remove();
	return false;
}

function agregar3() {
	$("#VAR").empty();
	$("#VAR").append('<p class="varinfo"><div style="text-align: right"><a href="" onclick="javascript:borrar3(); return false;"><img src=\"images/site/minus_.png\" alt=\"\" border=\"0\" /> <span style="color: blue; font-size: 12px;">[ Esborrar ]</span></a></div><br />'
	                  +'<span title="Adreça web del template">[template_URL]</span><span title="Estil del fons">[fons]</span>'
	                  +'<span title="Imatge del header esquerra">[image_header_left]</span><span title="Imatge del header central">[image_header_center]</span>'
	                  +'<span title="Imatge del header dreta">[image_header_right]</span><span title="Imatge del logo">[logo]</span><span title="Variable del nº de buttletí">[butlleti]</span>'
                    +'<span title="Data de enviament">[data]</span><span title="texte a posar (obligatoria)">[texte]</span><span title="Imatge del cos esquerra">[image_body_left]</span>'
                    +'<span title="Imatge del cos dreta">[image_body_right]</span><span title="Imatge del final de la pàgina esquerra">[image_bottom_left]</span><span title="Imatge del final de la pàgina centre">[image_bottom_center]</span>'
                    +'<span title="Imatge del final de la pàgina dreta">[image_bottom_right]</span>'
                    +'<br /><br /></p>');
}
function borrar3() {
	$("#VAR").empty();
	return false;
}

function previsualizar() {
	cual = document.editor.ta.value;
	$("#previsualizacion").empty();
	$("#previsualizacion").append('<p class="displayon1">Vista previa :<br /><br />'
	                              +'<div style="width: 550px; height: 500px; background-color: white; text-align: left; border: 1px solid black; overflow: auto">'
	                              +cual+'</div><br /><br />'
	                              +'<a href="" onclick="javascript:borrar2(); return false;">'
	                              +'<img src=\"images/site/minus_.png\" alt=\"\" border=\"0\" /> <span style="color: blue;">Esborrar Previtzualització</span></a></p>');
}
function previsualizarHTML() {
	cual = document.editor.ta.value;
	$("#previsualizacion").empty();
	$("#previsualizacion").append('<p class="displayon1">Vista previa :<br /><br />'
	                              +'<div style="width: 550px; height: 500px; background-color: white; text-align: left; border: 1px solid black; overflow: auto">'
	                              +cual+'</div><br /><br />'
	                              +'<a href="" onclick="javascript:borrar2(); return false;">'
	                              +'<img src=\"images/site/minus_.png\" alt=\"\" border=\"0\" /> <span style="color: blue;">Esborrar Previtzualització</span></a></p>');
}

function previsualizar3(cual) {
	//cual = document.editor.ta.value;
	alert(cual);
}

function borrar2() {
	$("#previsualizacion").empty();
	return false;
}


function agregar(){
//Para internet explorer
if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
var url="http://www.maderasmartinez.com"; //Cambia esta dirección por la de tu web
var titulo="Maderas Martinez Hnos. S.L. - Web oficial (c) 2011-2013 by elwizard"; //Cambia esta nombre por el de tu web
window.external.AddFavorite(url,titulo);
}
//Para Netscape y Firefox
else {
if(navigator.appName == "Netscape")
alert ("Presione Crtl+D para agregar a este sitio en sus Bookmarks");  //Puedes personalizar este mensaje
}
} 

var ns4class=''

function invert_allcheckboxes(headerfield, checkform, mask) {
	for (var i = 0; i < checkform.length; i++) {

		if (typeof(checkform[i].name) == "undefined" || (typeof(mask) != "undefined" && checkform[i].name.substr(0, mask.length) != mask))
			continue;

		if (!checkform[i].disabled)
			checkform[i].checked = headerfield.checked;
	}
}

function window1 (URL){ 
   window.open(URL,"Color","width=120,height=165,top=400,left=500,scrollbars=no,resizable=no") 
}
function window2 (URL){ 
   window.open(URL,"Color","width=50,height=500,top=100,left=500,scrollbars=yes,resizable=no") 
}
function window22 (URL){ 
   window.open(URL,"Color","width=450,height=200,top=100,left=500,scrollbars=no,resizable=no") 
}
function window3 (URL){ 
   window.open(URL,"Color","width=320,height=350,top=200,left=500,scrollbars=yes,resizable=no") 
}
function window4 (URL){ 
   window.open(URL,"Color","width=400,height=500,top=100,left=500,scrollbars=yes,resizable=no") 
}
function window5 (URL){ 
   window.open(URL,"Selector","width=900,height=600,top=0,left=200,scrollbars=yes,resizable=yes") 
}
function window6 (URL, myttdef){
	texte = document.editor.ta.value;
	
	// buscador de valores del formulario anterior
var tosearch = myttdef.split("$$$");

form = document;
var r=0;
var cual = "";
while (tosearch[r]!=null) {
	
  var length = form.editor.elements.length;
  
  for (var i = 0; i < length; i++ ) {
	
    element = form.editor[i].name;
    
    //alert(element+tosearch[r]);
    if(element == tosearch[r] ){
    	
      cual += tosearch[r]+"="+ form.editor[i].value +"$$$";
      
    }
  }
  r++;
}
	
window.open(URL+"?datos="+texte+"&datos1="+cual,"Selector","width=900,height=650,top=0,left=200,scrollbars=yes,resizable=yes") 
}

function window7 (URL){

	var input = document.editor.ta;
	
	if(typeof document.selection != 'undefined' && document.selection) {
		var texte = document.selection.createRange().text;
	}
  window.open(URL+"?datos="+texte,"Selector","width=700,height=350,top=200,left=200,scrollbars=yes,resizable=yes")
  
}

function window8 (URL){

	var input = document.editor.ta;
	
	if(typeof document.selection != 'undefined' && document.selection) {
		var texte = document.selection.createRange().text;
	}
  window.open(URL+"?datos="+texte,"Selector","width=800,height=650,top=0,left=200,scrollbars=yes,resizable=yes")
  
}
   
function resizeup(){
	document.editor.ta.rows--;
}

function resizedown(){
	document.editor.ta.rows++;
}

// inserta una etiqueta en el editor
function instag(tag){
	var input = document.editor.ta;
	
	if ((typeof document.selection != 'undefined') && (document.selection)) {
		var str = document.selection.createRange().text;
		input.focus();
		var sel = document.selection.createRange();
		sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
		sel.select();
		return;
	}else if(typeof input.selectionStart != 'undefined'){
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
	}else{
		input.value+=' ['+tag+']replace this text[/'+tag+']';
		return;
	}
}
function instag1(tag){
	var input = document.editor.ta;
	
	if(typeof document.selection != 'undefined' && document.selection) {
		var str = document.selection.createRange().text;
		input.focus();
		var sel = document.selection.createRange();
		sel.text = "[" + tag + "]";
		sel.select();
		return;
	}else if(typeof input.selectionStart != 'undefined'){
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + '['+tag+']' + insText + input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
	}else{
		input.value+=' ['+tag+'] ';
		return;
	}
}


function tag_move() {
	  var FoundErrors = '';
    var enterDIR   = prompt(text_enter_move, "lt");
    var enterTEXT = prompt(text_enter_text, "Text");

    if (!enterDIR) {
        FoundErrors += " " + error_no_dir;
    }
    if (!enterTEXT) {
        FoundErrors += " " + error_no_text;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    Inserttag2("[MOVE="+enterDIR+"]"+enterTEXT+"[/MOVE]", "", false);
}

function add_icon(theicon) {
    var iconShow = theicon;
    document.editor.ta.value += theicon 
}
function Inserttag2(thelist) {
    var obj_ta = document.editor.ta;
    obj_ta.value += iconShow;
}

/*
function tag_listUL() {
    var listvalue = "init";
    var thelist = "";
    while ( (listvalue != "") && (listvalue != null) ) {
        listvalue = prompt(list_prompt, "");
        if ( (listvalue != "") && (listvalue != null) ) {
            thelist = thelist+"[LI]"+listvalue+"[/LI]\n";
        }
    }
    if ( thelist != "" ) {
        Inserttag2('[UL]\n' + thelist + '[/UL]\n', '', false);
    }
}
*/
/*
function tag_listOL() {
    var listvalue = "init";
    var thelist = "";
    while ( (listvalue != "") && (listvalue != null) ) {
        listvalue = prompt(list_prompt, "");
        if ( (listvalue != "") && (listvalue != null) ) {
            thelist = thelist+"[LI]"+listvalue+"[/LI]\n";
        }
    }
    if ( thelist != "" ) {
        Inserttag2( "[OL]\n" + thelist + "[/OL]\n", "", false);
    }
}
*/

// MGS EDITOR
function Inserttag2(iconShow) {
    var obj_ta = document.editor.ta;
    obj_ta.value += iconShow;
}

function alterfont1(theval, thetag) {
    if (theval == 0)
        return;
    Inserttag2("[" + thetag + "=" + theval + "][/" + thetag + "]");
    document.editor.ffont.selectedIndex  = 0;
    document.editor.fsize.selectedIndex  = 0;
    document.editor.fcolor.selectedIndex = 0;
}

function tag_url() {
	
    var FoundErrors = '';
    var input = document.editor.ta;
	
	if ((typeof document.selection != 'undefined') && (document.selection)) {
		
		var enterURL   = prompt(text_enter_url, "http://");
       
    if (!enterURL) { FoundErrors += " " + error_no_url; }
    
    if (FoundErrors) {
        alert("Error! " + FoundErrors);
        return;
    }
			
		var str = document.selection.createRange().text;
		
		if (!str) { 
			
			var enterTITLE = prompt(text_enter_url_name, "Nom de la web");
			
			if (enterTITLE=="Nom de la web") {
        var str = enterURL;
      } else {
        var str = enterTITLE;
      }
    }
		
		input.focus();
		var sel = document.selection.createRange();		
		sel.text = "[URL=" + enterURL + "]" + str + "[/URL]";
		sel.select();
		return;
		
	}else if(typeof input.selectionStart != 'undefined'){
		
		var enterURL   = prompt(text_enter_url, "http://");
    
    if (!enterURL) { FoundErrors += " " + error_no_url; }
    
    if (FoundErrors) {
        alert("Error! "+FoundErrors);
        return;
    }
		
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		
		if (!insText) {
			var enterTITLE = prompt(text_enter_url_name, "Nom de la web");
			
			if (enterTITLE=="Nom de la web") {
        var insText = enterURL;
      } else {
        var insText = enterTITLE;
      }
    }
		
		input.value = input.value.substr(0, start) + "[URL=" + enterURL + "]" + insText +"[/URL]"+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
		
	}else{
		
		var enterURL   = prompt(text_enter_url, "http://");
    var enterTITLE = prompt(text_enter_url_name, "Nom de la web");
    
    if (!enterTITLE) { var enterTITLE = enterURL; }
    
    if (!enterURL) { FoundErrors += " " + error_no_url; }
    
    if (FoundErrors) {
        alert("Error! "+FoundErrors);
        return;
    }
		
		input.value += " [URL=" + enterURL + "]" + enterTITLE + "[/URL]";
		return;
		
	}

}


function tag_image() {

  var FoundErrors = '';
  var input = document.editor.ta;
	
	if ((typeof document.selection != 'undefined') && (document.selection)) {
			
		var str = document.selection.createRange().text;
		if (!str) {
      var enterURL   = prompt(text_enter_image, "http://");
      if (!enterURL) { FoundErrors += " " + error_no_url; }
      if (FoundErrors) {
        alert("Error! " + FoundErrors);
        return;
      }
      var str = enterURL;
    }
		input.focus();
		var sel = document.selection.createRange();		
		sel.text = "[IMG]" + str + "[/IMG]";
		sel.select();
		return;
		
	}else if(typeof input.selectionStart != 'undefined'){
		
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		
		if (!insText) {
      var enterURL   = prompt(text_enter_image, "http://");
      if (!enterURL) { FoundErrors += " " + error_no_url; }
      if (FoundErrors) {
        alert("Error! " + FoundErrors);
        return;
      }
      var insText = enterURL;
    }
		
		input.value = input.value.substr(0, start) + "[IMG]" + insText +"[/IMG]"+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
		
	} else {
		
		var enterURL   = prompt(text_enter_image, "http://");
    if (!enterURL) { FoundErrors += " " + error_no_url; }
    
    if (FoundErrors) {
        alert("Error! "+FoundErrors);
        return;
    }
		
		input.value += " [IMG]" + enterURL + "[/IMG]";
		return;
	}
}


function tag_email() {
	
	var FoundErrors = '';
  var input = document.editor.ta;
	
	if ((typeof document.selection != 'undefined') && (document.selection)) {
			
		var str = document.selection.createRange().text;
		if (!str) {
      var emailAddress = prompt(text_enter_email, "");
      if (!emailAddress) {
        alert(error_no_email);
        return;
      }
      var str = emailAddress;
    }
		input.focus();
		var sel = document.selection.createRange();		
		sel.text = "[EMAIL]" + str + "[/EMAIL]";
		sel.select();
		return;
		
	}else if(typeof input.selectionStart != 'undefined'){
				
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		
		if (!insText) {
      var emailAddress = prompt(text_enter_email, "");
      if (!emailAddress) {
        alert(error_no_email);
        return;
      }
      var insText = emailAddress;
    }
		
		input.value = input.value.substr(0, start) + "[EMAIL]" + insText +"[/EMAIL]"+ input.value.substr(end);
		input.focus();
		input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
		return;
		
	} else {
		
		var emailAddress = prompt(text_enter_email, "");
    if (!emailAddress) {
        alert(error_no_email);
        return;
    }
		
		input.value += " [EMAIL]" + emailAddress + "[/EMAIL]";
		return;
	}
    
}



function tag_media() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_media, "http://");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    Inserttag2("[MEDIA]"+enterURL+"[/MEDIA]", "", false);
}

function tag_flash1() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_flash, "http://");
    var fwidth = prompt(text_enter_fwidth , "");
    var fheight = prompt(text_enter_fheight , "");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    Inserttag2("[FLASH="+fwidth+","+fheight+"]"+enterURL+"[/FLASH]", "", false);
}
function insertbr() {
    Inserttag2("<br />", "", false);
}

// END MGS EDITOR

/*
	(C) 2007 Chuug. All rights reserved.
	twitthis.com
*/
var TwitThis = {
	pop : function () {
		return window.open("http://twitthis.com/twit?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "TwitThisPop", "width=600, height=500, location, status, scrollbars, resizable");
	}
}

/* ESTAS FUNCIONES SON PARA MARCAR Y DESMARCAR LOS POSTS EN EL FORO, PARA MULTIPROPÓSITO */
/* (C) MGS 2010-2012 por elwizard */

/* marca todos los checkboxs */
function mark_all(){ 
   for (i=0;i<document.myoptions.elements.length;i++) 
      if(document.myoptions.elements[i].type == 'checkbox') 
         document.myoptions.elements[i].checked=1 
} 

/* desmarca todos los checkboxs */
function unmark_all(){ 
   for (i=0;i<document.myoptions.elements.length;i++) 
      if(document.myoptions.elements[i].type == 'checkbox') 
         document.myoptions.elements[i].checked=0 
}

/* cambia el estado del TD dependiendo si lo seleccionamos o no (Válido para IE y FF) */
function change_style(myObj,xstate,dirimage){
	  
  thisObj = document.getElementById(myObj);
  
	if (xstate == true) {
	  
    thisObj.style.background = 'url(\'templates/'+dirimage+'images/post_td_inlined.jpg\') repeat-x';
	  createCookie('ext_post_'+myObj,'checked',10);
	  
	} else {

    thisObj.style.background = 'url(\'templates/'+dirimage+'images/post_td_head.jpg\') repeat-x';
    eraseCookie('ext_post_'+myObj);
	
	}
}

// marca todos los TD's, y les cambia de color. Pone también cookies
function mark_all_tds(total,dirimage){
	
	var total_ar = total;
	
  for (i=0; i<total_ar; i++){
  	
  	myObj = "mark"+my_array[i];
    thisObj = document.getElementById(myObj);  
    thisObj.style.background = 'url(\'templates/'+dirimage+'images/post_td_inlined.jpg\') repeat-x';
	  createCookie('ext_post_'+myObj,'checked',10);

  }
}

// desmarca todos los TD's, y les restura el color. Quita cookies
function quit_all_tds(total,dirimage){
	
	var total_ar = total;
		
  for (i=0; i<total_ar; i++){
  	
  	myObj = "mark"+my_array[i];
    thisObj = document.getElementById(myObj);  
    thisObj.style.background = 'url(\'templates/'+dirimage+'images/post_td_head.jpg\') repeat-x';
    eraseCookie('ext_post_'+myObj);

  }
}


/* crea una cookie */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* lee la cookie */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* borra la cookie */
function eraseCookie(name) {
	createCookie(name,"",-1);
}




